package top.infopub.mgr.sys.vo;


import java.util.ArrayList;
import java.util.List;


public class LayTreeVo {

    /**
     * 节点唯一索引值，用于对指定节点进行各类操作
     */
    private String id;

    /**
     * 节点标题
     */
    private String title;

    /**
     * 节点字段名
     */
    private String field;

    /**
     * 点击节点弹出新窗口对应的 url
     */
    private String href;

    /**
     * 节点是否初始展开，默认 false
     */
    private boolean spread;

    /**
     * 节点是否为禁用状态。默认 true
     */
    private boolean disabled = true;

    /**
     * 节点是否叶子节点
     */
    private boolean leaf;

    /**
     * 是否是最后一级父菜单  true=是 对于此菜单要异步加载下面的权限按钮选中情况 
     */
    private boolean lastStep = false;

    private List<LayTreeVo> children = new ArrayList<LayTreeVo>();

    public List<LayTreeVo> getChildren() {
        return this.children;
    }

    public void setChildren(List<LayTreeVo> children) {
        this.children = children;
    }

    private boolean checked;

    public boolean isChecked() {
        return this.checked;
    }

    public void setChecked(boolean checked) {
        this.checked = checked;
    }

    public String getHref() {
        return this.href;
    }

    public void setHref(String href) {
        this.href = href;
    }

    // 是否父节点
    private String bisroot;

    // 父节点ID
    private String sparentid;

    private String attributes;

    public String getBisroot() {
        return bisroot;
    }

    public String getAttributes() {
        return attributes;
    }

    public void setAttributes(String attributes) {
        this.attributes = attributes;
    }

    public void setBisroot(String bisroot) {
        this.bisroot = bisroot;
    }

    public String getSparentid() {
        return this.sparentid;
    }

    public void setSparentid(String sparentid) {
        this.sparentid = sparentid;
    }

    public String getId() {
        return this.id;
    }

    public boolean isLeaf() {
        return this.leaf;
    }

    public void setLeaf(boolean leaf) {
        this.leaf = leaf;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getField() {
        return field;
    }

    public void setField(String field) {
        this.field = field;
    }

    public boolean isSpread() {
        return spread;
    }

    public void setSpread(boolean spread) {
        this.spread = spread;
    }

    /**
     * 检查儿子有没有被选中，儿子被选中了，就选中自己，如果一个儿子也没有被选中，撤销自己
     */
    public void checkall() {
        if (this.isLeaf()) return;
        int size = children.size();
        LayTreeVo node;
        boolean ch = false;
        for (int i = size - 1; i >= 0; i-- ) {
            node = children.get(i);
            node.checkall();
            if (node.checked) ch = true;
        }
        checked = ch;
    }

    public void removeNoRight() {
        int size = children.size();
        LayTreeVo node;
        for (int i = size - 1; i >= 0; i-- ) {
            node = children.get(i);
            node.removeNoRight();
            if ((!node.isLeaf()) && node.getChildren().size() == 0) {
                children.remove(i);
            }
        }
    }

    public boolean isDisabled() {
        return disabled;
    }

    public void setDisabled(boolean disabled) {
        this.disabled = disabled;
    }

    public boolean isLastStep() {
        return lastStep;
    }

    public void setLastStep(boolean lastStep) {
        this.lastStep = lastStep;
    }
}
